package br.com.Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.Dao.UsuarioClienteDao;
import br.com.Dao.UsuarioComercianteDao;
import br.com.Modelo.UsuarioCliente;
import br.com.Modelo.UsuarioComerciante;

/**
 * Servlet implementation class editar_usuario_cliente
 */
@WebServlet("/cliente/editar_usuario_cliente")
public class editar_usuario_cliente extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public editar_usuario_cliente() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		// TODO Auto-generated method stub
				UsuarioCliente cliente = new UsuarioCliente();
				cliente.setLogin(request.getParameter("login_user"));	
				cliente.setSenha(request.getParameter("senha_user"));
				cliente.setNome(request.getParameter("nome_user"));
			    cliente.setEnd(request.getParameter("end_user"));
			    cliente.setEmail(request.getParameter("email_user"));
				cliente.setTelefone(request.getParameter("tel_user"));
				cliente.setId(Long.parseLong(request.getParameter("id_cliente")));
			    //String perfil_pagina = request.getParameter("perfil_pagina"); 
				
				  System.out.print("entrou aqiu");
			  

		   	UsuarioClienteDao dao = new UsuarioClienteDao();	   
		   	

		   	
		    if(cliente.getLogin()==""||
		            cliente.getSenha()=="" ||
		            cliente.getNome() == "" || 
		            cliente.getEnd() == ""||         
		            cliente.getEmail() == ""){
		          	
		    	request.getRequestDispatcher("config_conta.jsp?check-cad=Campos Invalido!!!").forward(request, response);
		          //response.sendRedirect("/plataforma_marketing/admin/config_admin.jsp?check-cad=Campos Invalido!");
		          
		    }else if(dao.verificaUsuario(cliente.getId(),cliente.getLogin(),cliente.getEmail())==1){
				
		    	System.out.println("entroi valida usuario");
		    	request.getRequestDispatcher("config_conta.jsp?check-cad=Login ou Email já Cadastrado!!").forward(request, response);
		    	 // response.sendRedirect("/plataforma_marketing/admin/config_admin.jsp?check-cad=Login ou Cnpj já Cadastrado!!");
		    	//response.sendRedirect("cadastro.jsp?check-cad=Campos Invalidos!!");
		    	
		    	
		    	
		    }else{   	
		   
		   	    dao.updateCliente(cliente);
		   	    response.sendRedirect("/plataforma_marketing/cliente/config_conta.jsp?check-ok= Conta Atualizado!");
		   	    
		    }
		
		
		
	}

}
